package cn.ghf.quartz.job;

import cn.ghf.basic.util.QuartzJobInfo;
import cn.ghf.order.domain.AdoptOrder;
import cn.ghf.order.mapper.AdoptOrderMapper;
import cn.ghf.pay.domain.PayBill;
import cn.ghf.pay.mapper.PayBillMapper;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

public class MainJob implements Job{

    @Autowired
    private AdoptOrderMapper adoptOrderMapper;

    @Autowired
    private PayBillMapper payBillMapper;
    /**
     * 订单超时，没有支付，取消订单，取消支付单
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取参数
        QuartzJobInfo info = (QuartzJobInfo)jobExecutionContext.getJobDetail().getJobDataMap().get("params");
        String paySn = info.getParams().get("paySn").toString();
        //通过sn查询更新订单
        AdoptOrder adoptOrder = adoptOrderMapper.loadBySn(paySn);
        adoptOrder.setState(-1); //取消订单状态
        adoptOrderMapper.update(adoptOrder);
        //更新支付单
        PayBill payBill = payBillMapper.loadByUnionPaySn(paySn);
        payBill.setState(-1);
        payBillMapper.update(payBill);
    }
}
